home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / mandlbx1.arc / MANDELS.S < prev    next >
Text File  |  1985-11-20  |  3KB  |  141 lines

  1. *    long                /* count remaining if >2 */
  2. *    mandels(count, cr,ci,  zr,zi)
  3. *    long count,  cr,ci,  *zr,*zi;
  4. *          where all but count are integers scaled by 2^-26
  5.  
  6.     .globl _mandels
  7.  
  8. * a0 = c real
  9. * a1 = c imag
  10. * d0 = z real
  11. * d1 = z imag
  12. * a2 = count
  13. _mandels:
  14.     link    a6,#-4
  15.     movem.l    d1-d7/a0-a5,-(a7)    * save temp registers
  16.  
  17. * Fetch C Args:
  18.     move.l    8(a6),a2    * count
  19.     move.l    12(a6),d0    * cr
  20.     asl.l    #2, d0
  21.     move.l    d0,a0
  22.     move.l    16(a6),d1    * ci
  23.     asl.l    #2, d1
  24.     move.l    d1, a1
  25.  
  26.     move.l    20(a6),a3    * *zr
  27.     move.l    (a3),d0
  28.     asl.l    #2, d0
  29.     move.l    24(a6),a3    * *zi
  30.     move.l    (a3),d1
  31.     asl.l    #2, d1
  32.  
  33.     move.l    a0,d0        first iteration is fast!
  34.     move.l    a1,d1        
  35.  
  36. loop:    move.l    d0, d2        * compute zr^2
  37.     bpl    lab1
  38.     neg.l    d2
  39. lab1    move.l    d2, d4        Zh  Zl
  40.     swap    d4        Zl  Zh
  41.     mulu    d2, d4        Ah  Al   = Zh(16)*Zl(16)
  42.     swap    d2        Zl  Zh
  43.     mulu    d2, d2        Bh  Bl   = Zh(16)*Zh(16)
  44.     clr.w    d4        
  45.     swap    d4        0   Ah
  46.     add.l    d4, d2
  47.     add.l    d4, d2        Bh  Bl+Ah+Ah
  48.  
  49.     move.l    d1, d3        * compute zi^2
  50.     bpl    lab2
  51.     neg.l    d3
  52. lab2    move.l    d3, d4
  53.     swap    d4
  54.     mulu    d3, d4        * hi*lo
  55.     swap    d3
  56.     mulu    d3, d3        * hi^2
  57.     clr.w    d4
  58.     swap    d4        * >>16
  59.     add.l    d4, d3
  60.     add.l    d4, d3
  61.  
  62.     move.l    d2, d4        * end test (zi^2)+(zr^2)>4
  63.     add.l    d3, d4
  64.  
  65. *!!! debug section
  66. *    asr.l   #1,d1
  67. *    add.l    d1,d0
  68. *    asl.l   #4,d4
  69. *    move.l    d4,d0
  70. *    clr.w    d0
  71. *    swap    d0
  72. *    bra    done1
  73. *!!! end debug
  74.  
  75.     cmp.l    #$04000000, d4
  76.     bcc    done        * (bhs) if >=4
  77.  
  78.     asl.l    #4, d2        * normalize
  79.     asl.l    #4, d3
  80.  
  81.     exg    d2, d0        * zr' = cr + zr^2 - zi^2
  82.     add.l    a0, d0        *  old zr left in d2 for zi' calc
  83.     bvs    doneq        * terminate here for next iter if zr>=2
  84.     sub.l    d3, d0
  85.     bvs    doneq        * also if zr<=-2
  86.  
  87. * compute zi'
  88. * d7 = sign
  89.     clr.l    d7
  90.     tst.l    d2
  91.     bpl    lab3
  92.     neg.l    d2
  93.     not.l    d7
  94. lab3:    tst.l    d1
  95.     bpl    lab4
  96.     neg.l    d1
  97.     not.l    d7
  98. lab4:    move.l    d1, d5        |Zi|
  99.     swap    d5        lsw = |Zi|.hi
  100.     swap    d2        lsw = |Zr|.hi
  101.     mulu    d2, d5        |Zr|.hi  *  |Zi|.hi
  102.     move.l    d1, d3        lsw = |Zi|.lo
  103.     mulu    d2, d3        |Zi|.lo  *  |Zr|.hi
  104.     swap    d2        lsw = |Zr|.lo
  105. *    move.l    d1, d6
  106. *    mulu    d2, d6        * d6 = d2.lo * d1.lo
  107. *    clr.w    d6
  108. *    swap    d6        * bits 32..47 of result in low word
  109. *    add.l    d6, d3
  110. *    bcc    lab5
  111. *    add.l    #$10000, d5
  112. lab5:    swap    d1        lsw = |Zi|.hi
  113.     mulu    d2, d1        |Zi|.hi  *  |Zr|.lo
  114.     add.l    d3, d1        (|Zi|.hi*|Zr|.lo) + (|Zi|.lo*|Zr|.hi)
  115.     asl.l    #5, d5
  116.     moveq    #11, d2        normalize and *2
  117.     lsr.l    d2, d1
  118.     add.l    d5, d1
  119.     tst.l    d7
  120.     bpl    lab7        put back sign
  121.     neg.l    d1
  122. lab7    add.l    a1, d1
  123.  
  124.     subq.l    #1,a2    * also terminate if iteration count expired
  125.     move.l    a2,d5
  126.     bne    loop
  127.  
  128. done:    move.l    20(a6),a3    * *zr
  129.     asr.l    #2, d0
  130.     move.l    d0,(a3)
  131.     move.l    24(a6),a3    * *zi
  132.     asr.l    #2, d1
  133.     move.l    d1,(a3)
  134.  
  135.     move.l    a2, d0        * return count as value
  136. done1:    movem.l    (a7)+,d1-d7/a0-a5    * restore temp registers
  137.     unlk    a6
  138.     rts
  139.  
  140. doneq    illegal            should never get here
  141.